<template>
  <i-card class="margin-bottom-10" dis-hover>
    <p slot="title">评论</p>
    <i-form @submit.native.prevent="onSubmit()">
      <i-input v-model="form.content" type="textarea" placeholder="文明上网 理性发言" :rows="4"></i-input>
      <i-button type="primary" html-type="submit" class="margin-top-10">发表评论</i-button>
    </i-form>
  </i-card>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  props: ['objectId'],
  data() {
    return {
      form: {
        objectId: null,
        content: null
      }
    }
  },
  watch: {
    objectId(val) {
      this.form.objectId = val
    }
  },
  mounted() {
    this.form.objectId = this.objectId
  },
  methods: {
    ...mapActions({
      saveComment: 'saveComment'
    }),
    onSubmit() {
      if (!this.form.content) return
      this.saveComment({
        form: this.form,
        callback(data) {
          if (data.saved) {
            this.form.content = null
          }
        }
      })
    }
  }
}
</script>

<style>
</style>
